package com.kevin.ymqquan;

import com.kevin.ymqquan.fragment.ClubFragment;
import com.kevin.ymqquan.fragment.CoachFragment;
import com.kevin.ymqquan.fragment.Home3Fra;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends FragmentActivity implements OnClickListener {

	private TextView mBt1, mBt2, mBt3;
	private FragmentManager mFM = null;
	
	LinearLayout content_container, content_container2;
	Intent m_Intent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		init();

		changePerson();
	}


	private void init() {

		mBt1 = (TextView) findViewById(R.id.tab_bt_1);
		mBt2 = (TextView) findViewById(R.id.tab_bt_2);
		mBt3 = (TextView) findViewById(R.id.tab_bt_3);

		mBt1.setOnClickListener(this);
		mBt2.setOnClickListener(this);
		mBt3.setOnClickListener(this);
		mBt1.setSelected(true);
		content_container = (LinearLayout) findViewById(R.id.content_container);
		content_container2 = (LinearLayout) findViewById(R.id.content_container2);
		
	}

	
	View v1, v2;

	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.tab_bt_1:
			mBt1.setSelected(true);
			mBt2.setSelected(false);
			mBt3.setSelected(false);
			changePerson();
			break;
		case R.id.tab_bt_2:
			mBt1.setSelected(false);
			mBt2.setSelected(true);
			mBt3.setSelected(false);
			changeBussiness();
			break;
		case R.id.tab_bt_3:
			mBt1.setSelected(false);
			mBt2.setSelected(false);
			mBt3.setSelected(true);
			changeMessage();
			break;
		default:
			break;
		}
	}

	//TEST
	/**
	 * 切换fragement
	 */
	private void changePerson() {
		Fragment f = new ClubFragment();
		if (null == mFM)
			mFM = getSupportFragmentManager();
		FragmentTransaction ft = mFM.beginTransaction();
		ft.replace(R.id.content_container, f);
		ft.commit();
	}

	/**
	 * 切换fragement
	 */
	public void changeBussiness() {
		Fragment f = new CoachFragment();
		if (null == mFM)
			mFM = getSupportFragmentManager();
		FragmentTransaction ft = mFM.beginTransaction();
		ft.replace(R.id.content_container, f);
		ft.commit();
	}

	/**
	 * 切换fragement
	 */
	public void changeMessage() {
		Fragment f = new Home3Fra();
		if (null == mFM)
			mFM = getSupportFragmentManager();
		FragmentTransaction ft = mFM.beginTransaction();
		ft.replace(R.id.content_container, f);
		ft.commit();
	}

	/**
	 * 切换fragement
	 */
	public void changeSetting() {
		Fragment f = new Home1Fra();
		if (null == mFM)
			mFM = getSupportFragmentManager();
		FragmentTransaction ft = mFM.beginTransaction();
		ft.replace(R.id.content_container, f);
		ft.commit();
	}


}
